/**
 * 图片层
 */
define(['createjs'],function(createjs){
	var ImgLayer = function(layer){
		this._layer = layer;
		this._imgKeyList = {};
		/**
		 * 设置图片map
		 * @param {String} src map的Key
		 * @param {Object} obj 要缓存的图片
		 */
        this._setImgMap = function(src,obj){
			this._imgKeyList[src] = obj;
        };

		/**
		 * 得到图片map
		 * @param {String} src map的Key
		 */
		this._getImgMap = function(src){
			return this._imgKeyList[src];
		};

		/**
		 * 画画
		 * @param {Object} imageObj 要画的对象
		 */
		this.draw = function(imageObj){
			//如果isAdd为0则不画出来
			if(!imageObj.isAdd){
				var myObj = this._getImgMap(imageObj.relativeSourcePath);
				this._layer.removeChild(myObj);
			}else{
				var myObj = new createjs.Bitmap(imageObj.imageObj);
				var angle = parseInt(imageObj.angle*180/Math.PI);
				//TODO 白板语言的bug！！！！
				if((angle / 90) % 2 == 0){
					myObj.set({
						regX : imageObj.imageObj.width/2,
						regY : imageObj.imageObj.height/2,
						x:imageObj.x + imageObj.width/2,
						y:imageObj.y + imageObj.height/2,
						rotation :imageObj.angle*180/Math.PI,
						scaleX : imageObj.width/imageObj.imageObj.width,
						scaleY : imageObj.height/imageObj.imageObj.height
					});
				}else{
					myObj.set({
						regX : imageObj.imageObj.height/2,
						regY : imageObj.imageObj.width/2,
						x:imageObj.x + imageObj.height/2,
						y:imageObj.y + imageObj.width/2,
						rotation :imageObj.angle*180/Math.PI,
						scaleX : imageObj.height/imageObj.imageObj.width,
						scaleY : imageObj.width/imageObj.imageObj.height
					});
				}
				
				this._layer.addChild(myObj);
				this._setImgMap(imageObj.relativeSourcePath,myObj);
			}
		}
		
		/**
		 * 清空
		 */
		this.clear = function(){
			this._layer.removeAllChildren();
		}
	};
	return ImgLayer;
});